package com.example.rabbitmqdemo.producer;

import com.example.rabbitmqdemo.config.RabbitMQConfig;
import com.rabbitmq.client.MessageProperties;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessageToQueues1(String message) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,RabbitMQConfig.ROUTING_KEY_1, message);
    }
    public void sendMessageToQueues2(String message) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,RabbitMQConfig.ROUTING_KEY_2, message);
    }
    public void sendvipMessage(String message) {
        Message vipMessage =new Message(message.getBytes());
        vipMessage.getMessageProperties().setPriority(10);
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,RabbitMQConfig.VIP_ROUTER_KEY, vipMessage);
    }
    public void sendnormalMessage(String message) {
        Message normalMessage =new Message(message.getBytes());
        normalMessage.getMessageProperties().setPriority(1);
        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,RabbitMQConfig.ROUTING_KEY_1, normalMessage);
    }
    public void sendDelayedMessage(String message) {
     rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_NAME,"delayed",message);

    }
}    